package com.by.yz.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.by.yz.R;
import com.by.yz.activity.base.BaseActivity;
import com.by.yz.custom.TechnologyTeamDividerItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 123 on 2016/10/8.
 */
public class SelectSeriesOfCarActivity extends BaseActivity {

    private RecyclerView series;
    private List<String> datas=new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_series_of_car_activity);
        initDatas();
        initView();

    }

    private void initDatas() {
        datas.add("宝马1系");
        datas.add("宝马3系");
        datas.add("宝马5系");
        datas.add("宝马7系");
        datas.add("宝马x系");
    }

    private void initView() {
        series=(RecyclerView) findViewById(R.id.series_recyclerView);
        final String seriesName = getIntent().getStringExtra("brandOfCar");
        setToolbarTitle(seriesName);


        series.setLayoutManager(new LinearLayoutManager(series.getContext()));
        series.setAdapter(new SeriesRecyclerViewAdapter(this,
                datas));
        series.addItemDecoration(new TechnologyTeamDividerItemDecoration(this,TechnologyTeamDividerItemDecoration.VERTICAL_LIST));


    }


    public  class SeriesRecyclerViewAdapter
            extends RecyclerView.Adapter<SeriesRecyclerViewAdapter.ViewHolder> {

        private final TypedValue mTypedValue = new TypedValue();
        private int mBackground;
        private List<String> mValues;

        public  class ViewHolder extends RecyclerView.ViewHolder {
            public String seriesName;

            public final View mView;
            public final TextView series;

            public ViewHolder(View view) {
                super(view);
                mView = view;
                series = (TextView) view.findViewById(R.id.series);
            }

//            @Override
//            public String toString() {
//                return super.toString() + " '" + mTextView.getText();
//            }
        }

        public String getValueAt(int position) {
            return mValues.get(position);
        }

        public SeriesRecyclerViewAdapter(Context context, List<String> items) {
//            context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true);
//            mBackground = mTypedValue.resourceId;
            mValues = items;



        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.series_of_car_item, parent, false);
            // view.setBackgroundResource(mBackground);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(final ViewHolder holder, int position) {
            holder.seriesName=mValues.get(position);
            holder.series.setText(holder.seriesName);

            holder.mView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(SelectSeriesOfCarActivity.this, SelectTyleOfCarActivity.class);
                    intent.putExtra("seriesOfCar",holder.seriesName);
                    SelectSeriesOfCarActivity.this.startActivity(intent);
                    SelectSeriesOfCarActivity.this.overridePendingTransition(R.anim.push_left_in,
                            R.anim.push_left_out);
                }
            });

        }

        @Override
        public int getItemCount() {
            return mValues.size();
        }
    }

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true;
//        getMenuInflater().inflate(R.menu.mm, menu);
//        return true;
//    }

//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        switch (item.getItemId()) {
//           case android.R.id.home:
//                Toast.makeText(this, "home", Toast.LENGTH_SHORT).show();
//                return true;
//            case R.id.m1:
//                Toast.makeText(this, "m1", Toast.LENGTH_SHORT).show();
//                break;
//            case R.id.m2:
//                Toast.makeText(this, "m2", Toast.LENGTH_SHORT).show();
//                break;
//
//        }
//        return super.onOptionsItemSelected(item);
//    }
}
